﻿using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using IQIGame.Onigao.Logic;

namespace IQIGame.Onigao.GamePlay
{
    public class StoryContext
    {
        public string storyName;
        public StoryConfig config;
        public int curIndex;
        public TViewEntity conditionEntity;
        
        public StoryNodeConfig curNode => this.config?.nodes[this.curIndex];

        // 历史记录Index，若有选项第二位为选项
        public List<(int, int)> history = new List<(int, int)>();

        // 记录选项中的服务
        public List<int> choose = new List<int>();

        private Func<List<int>, UniTask> _sendServiceFunc;

        public void InitFunc(Func<List<int>, UniTask> sendServiceFunc)
        {
            this._sendServiceFunc = sendServiceFunc;
        }

        public UniTask SendEnd()
        {
            if (this._sendServiceFunc == null)
            {
                return default;
            }
            var rChoose = this.config.hasService ? this.choose : null;
            return this._sendServiceFunc.Invoke(rChoose);
        }

        public bool CheckCondition(int cid)
        {
#if UNITY_EDITOR
            if (StoryClientUtil.IsEditorMode)
            {
                return true;
            }
#endif
            (bool isOK, _) = GameplayAreaManager.Instance.curSceneArea.CheckCondition(cid, this.conditionEntity);
            return isOK;
        }
    }

    public enum EStoryBackGroundType
    {
        // Delete : 删除
        [UnityEngine.InspectorName("删除")] Delete = -1,
        // None : 
        [UnityEngine.InspectorName("不变")] None = 0,
        // BlurGenerate : 生成的模糊背景
        [UnityEngine.InspectorName("模糊背景")] BlurGenerate = 1,
        // Asset : 资源图片
        [UnityEngine.InspectorName("资源背景")] Asset = 2,
        // Roll : 背景滚动播放
        [UnityEngine.InspectorName("滚动背景")] Roll = 3,
    }
}